cmake_minimum_required(VERSION 3.10)

set(bin_dir "${CMAKE_SOURCE_DIR}/bin")

file(GLOB src "*.h" "*.cpp")

add_executable(${PROJECT_NAME} ${src})

###############################################################################
# find 3rd support
###############################################################################

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/common)

if (WIN32)
    find_package(glm CONFIG REQUIRED)
    find_package(nlohmann_json CONFIG REQUIRED)

    find_package(spdlog CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog spdlog::spdlog_header_only)

    find_package(OpenMesh CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENMESH_LIBRARIES})
    target_include_directories(${PROJECT_NAME} PRIVATE ${OPENMESH_INCLUDE_DIRS})
else ()
    include(FindPkgConfig)
    pkg_check_modules(PKGS_DEP REQUIRED glm spdlog OpenMesh nlohmann_json)

    FOREACH(flag ${PKGS_DEP_CFLAGS})
        set(EXTRA_CFLGAS "${EXTRA_CFLGAS} ${flag}")
    ENDFOREACH(flag)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLGAS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLGAS}")
    target_link_libraries(${PROJECT_NAME} PRIVATE ${PKGS_DEP_LDFLAGS})
    target_include_directories(${PROJECT_NAME} PRIVATE ${PKGS_INCLUDE_DIRS})
endif ()

find_package(OpenSceneGraph REQUIRED osg osgDB osgText osgUtil osgGA osgViewer)
target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENSCENEGRAPH_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSCENEGRAPH_INCLUDE_DIRS})


###############################################################################
# config
###############################################################################

set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
target_compile_definitions(${PROJECT_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=1 GLM_FORCE_CTOR_INIT _USE_MATH_DEFINES)
